package com.karry.yl.web.elder;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.karry.commons.base.SuperController;
import com.karry.commons.vo.JsonResponse;
import com.karry.commons.vo.LayTableResponse;
import com.karry.yl.domain.elder.Transefer;
import com.karry.yl.service.elder.TranseferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 老人档案转入/转出 记录
 */

@Controller
@RequestMapping("/transefer")
public class TranseferController extends SuperController {
    @Autowired
    private TranseferService transeferService;

    @RequestMapping("/in")
    public String inListUI(){
        return "elder/transeferin/list";
    }

    @RequestMapping("/in/list")
    @ResponseBody
    public LayTableResponse inList(int page, int limit){
        Page<Transefer> transeferPage = transeferService.selectPage(new Page<Transefer>(page, limit),new EntityWrapper<Transefer>().eq("toId", currentUser.getOrgId()).eq("deleted",false).orderBy("createdTime",false));
        return new LayTableResponse(transeferPage.getRecords(),transeferPage.getTotal());
    }

    @RequestMapping("/out")
    public String listUI(){
        return "elder/transeferout/list";
    }

    @RequestMapping("/out/list")
    @ResponseBody
    public LayTableResponse list(int page, int limit){
        Page<Transefer> transeferPage = transeferService.selectPage(new Page<Transefer>(page, limit),new EntityWrapper<Transefer>().eq("fromId", currentUser.getOrgId()).eq("deleted",false).orderBy("createdTime",false));
        return new LayTableResponse(transeferPage.getRecords(),transeferPage.getTotal());
    }

    /**
     * 同意转档
     * @param
     * @return
     */
    @RequestMapping(path = "/out/agree")
    @ResponseBody
    public JsonResponse agree(Long id){
        transeferService.agree(id);
        return JsonResponse.success();
    }


    /**
     * 不同意转档
     * @param
     * @return
     */
    @RequestMapping(path = "/out/disagree")
    @ResponseBody
    public JsonResponse disagree(Long id,String msg){
        Transefer transefer = transeferService.selectById(id);
        transefer.setStatus(Transefer.STATUS_BH);
        transefer.setMsg(msg);
        transeferService.updateById(transefer);
        return JsonResponse.success();
    }
}
